<?php
namespace app\admin\taglib;
use think\template\TagLib;
use think\facade\View;
class Admin extends TagLib{
    /**
     * 定义标签列表
     */
    protected $tags   =  [
        'include'   => ['close'=>0],
        'hook'   => ['close'=>0],
        'formelem'   => ['close'=>0]
    ];
    public function tagFormElem($tag){
      
    }
    public function tagInclude($tag){
        $data = $this->tpl->get();
        extract($data);
        foreach($tag as $k=>$v){
            if($k=='file') continue;
            if(substr($v,0,1)=='$'){
                eval('$assign_d = '.$v.';');
                View::assign($k,$assign_d);
            }else{
                View::assign($k,$v);
            }
        }
        return View::fetch($tag['file']);
    }
    public function tagHook($tag){
        $data = $this->tpl->get();
        $hookname = $tag['name'];
        $contents = '';
        if(isset($data['nav']['hooks'][$hookname])){
            foreach($data['nav']['hooks'][$hookname] as $rr){
                $contents .= $rr['content'];
            }
        }
        return View::display($contents);
    }
}